#!/bin/sh
#
# For non-production boxes, starts a process to productionize the box after
# some period of time.
#

MONITOR_PATH="/tmp/gpio/ledcontrol"
MFG_MODE_FILE="$MONITOR_PATH/mfg_mode"

start() {
	# Turn it into a production unit.
	if is-fiberjack; then
		prod_unit=$(hnvram -qr PRODUCTION_UNIT)
		if [ -z "$prod_unit" ]; then
			setprodflag 2>&1 | logos setprodflag &
		elif [ "$prod_unit" = "0" ]; then
			mkdir -p $MONITOR_PATH
			touch $MFG_MODE_FILE
		fi
	fi
}

stop() {
	pkill -x setprodflag
}

case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	restart|reload)
		$0 stop; $0 start
		;;
	*)
		echo "Usage: $0 {start|stop|restart}"
		exit 1
esac
